#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: connector_demo.py 
@version:
@time: 2022/03/17 
"""
import inspect
import os
import sys

sys.path.append(os.getcwd())
import fire

from TapClientConnector import *
import db_info as _


def get_classes(arg):
    classes = {}
    cls_members = inspect.getmembers(arg, inspect.isclass)
    for name, _ in cls_members:
        classes.update({name: _})
    return classes


class TapConnectorPythonClient:

    def __init__(self, source_type, name, sql=''):
        self.sql = sql
        self.source_type = source_type
        self._db_info = getattr(get_classes(_).get(source_type), name)
        self.connector = TapClientConnector(self._db_info)

    @staticmethod
    def show_module():
        return get_classes(_)

    def show_class(self):
        return get_classes(_).get(self.source_type)

    def show_attr(self):
        return self._db_info

    def query(self):
        """
        查询语句结果获取
        :return:
        """
        return self.connector.tapclient_connector.query(self.sql)

    def show_dbs(self):
        """
        查询数据库包含库
        :return:
        """
        return self.connector.tapclient_connector.show_dbs()

    def show_tables(self):
        """
        查询数据库表包含表
        :return:
        """
        return self.connector.tapclient_connector.show_tables()

    def execute(self):
        """
        执行语句
        :return:
        """
        return self.connector.tapclient_connector.exec(self.sql)


if __name__ == '__main__':
    fire.Fire(TapConnectorPythonClient)
